package com.xbang.attendance.service.impl;


import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xbang.attendance.entity.order.DeliveryDetails;
import com.xbang.attendance.entity.stock.InventoryExchange;
import com.xbang.attendance.entity.system.Warehouse;
import com.xbang.attendance.service.MailService;
import com.xbang.core.service.SendMailService;
import com.xbang.core.utils.FreeMarkerUtils;



/**
 * @author huawei
 * @email alonelaval@gmail.com
 */
@Service("mailService")
public class MailServiceImpl implements MailService {
	@Autowired
	private SendMailService sendMailService;
	@Override
	public void send(String wareHouseCode, String region, String wareHouseName,
			String ascCode, String ascName, String poNo, String doNo,
			Set<DeliveryDetails> details, String to, String toNickname,
			String subject,String date) throws Exception {
		
		Map root =new HashMap();
		root.put("wareHouseCode", wareHouseCode);
		root.put("region",region);
		root.put("warehouseName", wareHouseName);
		root.put("ascCode", ascCode);
		root.put("ascName",ascName);
		root.put("details", details);
		root.put("poNo", poNo);
		root.put("doNo", doNo);
		root.put("date", date);
		
//		List<DeliveryDetails> delivery = new ArrayList<DeliveryDetails>();
//		for (DeliveryDetails deliveryDetails : details) {
//			delivery.add(deliveryDetails);
//		}
		
		String text = FreeMarkerUtils.processTemplateFile(root,"delivery2.html");
		sendMailService.send(to, toNickname, subject, text);
	}
	@Override
	public void sendMail(List<InventoryExchange> inventoryExchanges,Warehouse warehouse)
			throws Exception {
		Map root =new HashMap();
		root.put("inventoryExchanges", inventoryExchanges);
		String text = FreeMarkerUtils.processTemplateFile(root,"exchange.html");
		sendMailService.send(warehouse.getEmail(), "system", "仓储调货记录", text);
	}
	@Override
	public void sendMail(String to, String toNickname, String subject,String messageText,
			List<File> files,String... carbonCopys) throws Exception {
		sendMailService.send(to, toNickname, subject, messageText, files,carbonCopys);
	}

	

}

